package com.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import com.mapper.*;
import com.util.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class RenameService {
    @Resource
    private RenameDao renameDao;
    @Resource
    private C_inforDao c_inforDao;
    @Resource
    private C_userDao c_userDao;
    @Resource
    private F_inforDao f_inforDao;
    @Resource
    private F_userDao f_userDao;

    public Result<?> rename(Rename rename)  {
        DateTime dateTime=new DateTime();
        rename.setDatetime(dateTime.toString());
        renameDao.insertName(rename);
        C_infor c_infor=new C_infor();
        c_infor.setpId(rename.getpId());
        c_infor.setcName(rename.getnName());
        c_inforDao.updateName(c_infor);
        Result result=new Result();
        Result r=result.success(result);
        return r;
    }
    public Result<?> reAccount(Rename rename){
        DateTime dateTime=new DateTime();
        rename.setDatetime(dateTime.toString());
        C_infor c_infor=new C_infor();
        C_user c_user=new C_user();
        F_infor f_infor=new F_infor();
        F_user f_user=new F_user();
        c_infor.setcAccount(rename.getnAccount());
        c_infor.setpId(rename.getpId());
        c_user.setCAccount(rename.getnAccount());
        c_user.setpId(rename.getpId());
        f_infor.setcAccount(rename.getnAccount());
        f_infor.setpId(rename.getpId());
        f_user.setcAccount(rename.getnAccount());
        f_user.setpId(rename.getpId());
        c_userDao.updateAccount(c_user);
        c_inforDao.updateAccount(c_infor);
        f_userDao.updateAccount(f_user);
        f_inforDao.updateAccount(f_infor);
        Result result=new Result();
        Result r=result.success(result);
        return r;
    }
    public List<Rename> see(String p_id){
        Rename rename=new Rename();
        rename.setpId(p_id);
        return renameDao.select(rename);
    }
}
